package com.ctrip.framework.apollo.config.data.listener;

import com.ctrip.framework.apollo.core.utils.DeferredLogger;
import org.springframework.boot.context.event.ApplicationContextInitializedEvent;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.context.ApplicationListener;

/**
 * @author vdisk <vdisk@foxmail.com>
 */
public class ApolloDeferredLoggerApplicationListener implements ApplicationListener<SpringApplicationEvent> {

    @Override
    public void onApplicationEvent(SpringApplicationEvent event) {
        if (event instanceof ApplicationContextInitializedEvent) {
            DeferredLogger.replayTo();
        }
        if (event instanceof ApplicationFailedEvent) {
            DeferredLogger.replayTo();
        }
    }
}
